<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.lang.reflect.Method"%>
<%@page import="cn.edu.zjut.chopper.message.RemoteInterface"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Remote Interface Method List</title>
</head>
<body style="background-color: #AFEEEE; text-align: center;">
<jsp:include page="head.html"/>
<table width="800" align="center" >
	<tr style="background-color: #969696">
		<td><table align="center"><tr><td style="font-size:20pt;">Remote Interface Method List</td></tr></table></td>
	</tr>
<% 
	RemoteInterface ri = (RemoteInterface)request.getAttribute("remote_interface"); 
	Class interfaceClass = (Class)request.getAttribute("interface_class");
	out.println("<tr><td><table width=\"100%\">");
	out.println("<tr  style=\"background-color:#90EE90;\"><td width=\"25%\" style=\"font-weight:bold\">Registry Key:</td><td width=\"25%\">"+ri.getName()+"</td><td width=\"25%\" style=\"font-weight:bold \">Version:</td><td width=\"25%\">"+ri.getVersion()+"</td></tr>");
	out.println("<tr  style=\"background-color:#90EE90;\"><td width=\"25%\" style=\"font-weight:bold\">Class Name:</td><td width=\"25%\">"+ri.getInterfaceClassName()+"</td><td width=\"25%\" style=\"font-weight:bold \">Invoke Count:</td><td width=\"25%\">"+ri.getCount()+"</td></tr>");
	out.println("<tr  style=\"background-color:#90EE90;\"><td width=\"25%\" style=\"font-weight:bold\">Url:</td><td width=\"75%\" colspan=\"3\">"+ri.getUrl()+"</td></tr>");
	out.println("<tr  style=\"background-color:#90EE90;\"><td width=\"25%\" style=\"font-weight:bold\">Note:</td><td width=\"75%\" colspan=\"3\">"+ri.getNote()+"</td></tr>");
	out.println("</table></td></tr>");
	for(Method m : interfaceClass.getDeclaredMethods()){
		out.println("<tr><td><table  width=\"100%\">");
		out.println("<form action=\"/chopper/TestInterface\">");
		out.println("<input type=\"hidden\" name=\"action\" value=\"run_method\"/>");
		out.println("<input type=\"hidden\" name=\"Name\" value=\""+ri.getName()+"\"/>");
		out.println("<input type=\"hidden\" name=\"Url\" value=\""+ri.getUrl()+"\"/>");
		out.println("<input type=\"hidden\" name=\"Version\" value=\""+ri.getVersion()+"\"/>");
		out.println("<input type=\"hidden\" name=\"method_name\" value=\""+m.getName()+"\"/>");
		out.println("<tr style=\"background-color: #FFFF99;\"><td width=\"20%\" style=\"font-weight:bold\" >Return Type</td><td width=\"20%\" style=\"font-weight:bold\">Method name</td><td width=\"60%\" style=\"font-weight:bold\">Parameters</td></tr>");
		String returnType = m.getReturnType().toString();
		out.println("<tr style=\"background-color: #FFFF99;\"><td width=\"20%\">"+returnType.substring(returnType.lastIndexOf(".")+1,returnType.length())+"</td><td width=\"20%\">"+m.getName()+"</td><td width=\"60%\" align=\"left\">");
		int i=0;
		for(Class c : m.getParameterTypes()){
			i++;
			String paramType = c.toString();
			out.print(paramType.substring(paramType.lastIndexOf(".")+1)+":<input type=\"text\" size=\"10\" name=\"param"+i+"\"/>&nbsp;");
			out.print("<input type=\"hidden\" name=\"param_type"+i+"\" value=\""+paramType.substring(paramType.lastIndexOf(" ")+1)+"\"/>&nbsp;");
		}
		out.println("<input type=\"submit\" value=\"run\" />");
		out.println("</td></tr>");
		out.println("</form>");
		out.println("</table></td></tr>");
	}
%>
</table>
<jsp:include page="foot.html"/>
</body>
</html>